#pragma once
#include"RBTree.h"
namespace shuaiming
{
	template<class K, class V>
	class map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K,V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename shuaiming::RBTree<K, pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename shuaiming::RBTree<K, pair<const K, V>, MapKeyOfT>::Const_Iterator const_iterator;
		iterator begin() { return rbt.Begin(); }
		iterator end() { return rbt.End(); }
		const_iterator begin() const { return rbt.Begin(); }
		const_iterator end() const { return rbt.End(); }
		pair<iterator, bool> insert(const pair<K,V>& kv) { return rbt.Insert(kv); }
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = rbt.Insert({ key, V() });
			return ret.first->second;
		}
	private:
		RBTree<K, pair<const K, V>, MapKeyOfT> rbt;
	};
}